// ignore_for_file: use_build_context_synchronously

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:xvideos/hj_page/main_page/provider/msg_provider.dart';
import 'package:xvideos/routers/jump_router.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';
import 'package:video_player/video_player.dart';

import '../../../../hj_model/countdown_update_model.dart';

class ShortNewerTimerVip extends StatefulWidget {
  final VideoPlayerController? controller;

  const ShortNewerTimerVip({
    Key? key,
    this.controller,
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _ShortVideoSmallAdWidgetState();
  }
}

class _ShortVideoSmallAdWidgetState extends State<ShortNewerTimerVip> {
  Timer? _timer;

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      _loadData();
    });
  }

  void _loadData() async {
    MineMsgProvider().getNewUserCountdown();
    // startTimer
  }

  // void startTimer() {
  //   if (_timer != null) return;
  //   if ((VariableConfig.newerCountdown?.leftTimeSinceEpoch ?? 0) > 0) {
  //     _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
  //       if (mounted) {
  //         setState(() {});
  //       }
  //     });
  //   }
  // }

  @override
  Widget build(BuildContext context) {
    // if (VariableConfig.newerCountdown != null && (VariableConfig.newerCountdown?.leftTimeSinceEpoch ?? 0) > 0) {
    //   return Container(
    //     height: 32,
    //     margin: const EdgeInsets.only(top: 14),
    //     padding: EdgeInsets.symmetric(horizontal: 20),
    //     decoration: BoxDecoration(
    //       borderRadius: BorderRadius.circular(30),
    //       color: Color(0xffFACC15).withOpacity(0.12),
    //       border: Border.all(color: Color(0xffFACC15).withOpacity(0.1)),
    //     ),
    //     child: _getTimeOutUi(VariableConfig.newerCountdown!),
    //   );
    // }
    return SizedBox();
  }

  Widget _getTimeOutUi(Countdown countdown) {
    return GestureDetector(
      onTap: () async {
        widget.controller?.pause();
        await jumpToWalletPage();
        widget.controller?.play();
      },
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Text(
            "新人限时特惠 倒计时 ",
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
            style: TextStyle(
              color: Color(0xffFACC15),
              fontSize: 14,
            ),
          ),
          4.sizeBoxW,
          Text(
            "${countdown.leftTimeSinceEpoch.timeMSFormat}",
            style: TextStyle(
              color: Color(0xffFACC15),
              fontSize: 14,
            ),
          ),
        ],
      ),
    );
  }

  @override
  void dispose() {
    _timer?.cancel();
    super.dispose();
  }
}
